//RenewInsureOrderModel
//2020-08-28 16:27:29

package models

import (
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/models/base"
	"git.900sui.cn/kc/kcgin/orm"
)

//表结构体
type RenewInsureOrderModel struct {
	Model *base.Model
	Field RenewInsureOrderModelField
}

//表字段
type RenewInsureOrderModelField struct {
	T_table           string `default:"renew_insure_order"`
	F_id              string `default:"id"`
	F_order_sn        string `default:"order_sn"`
	F_pay_sn          string `default:"pay_sn"`
	F_renew_insure_id string `default:"renew_insure_id"`
	F_total_amount    string `default:"total_amount"`
	F_amount          string `default:"amount"`
	F_create_time     string `default:"create_time"`
	F_pay_channel     string `default:"pay_channel"`
	F_clearing_id     string `default:"clearing_id"`
	F_clearing_status string `default:"clearing_status"`
}

//初始化
func (r *RenewInsureOrderModel) Init(ormer ...orm.Ormer) *RenewInsureOrderModel {
	functions.ReflectModel(&r.Field)
	r.Model = base.NewModel(r.Field.T_table, ormer...)
	return r
}

//新增数据
func (r *RenewInsureOrderModel) Insert(data map[string]interface{}) int {
	result, _ := r.Model.Data(data).Insert()
	return result
}

// 更新状态
func (r *RenewInsureOrderModel) UpdateByClingStatus(payChannel, clearingStatus int, clearingId string, data map[string]interface{}) (int, error) {
	return r.Model.Where(map[string]interface{}{
		r.Field.F_pay_channel:     payChannel,
		r.Field.F_clearing_id:     clearingId,
		r.Field.F_clearing_status: clearingStatus,
	}).Data(data).Update()
}
